package com.gaoxin.api.service.stuservice;

import java.util.Calendar;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gaoxin.api.dao.studao.QueryStuNumberDao;
import com.gaoxin.api.entity.stuentity.StuInfoEntity;

/**
 * 查询学生人数
 * @author maxue
 *
 */
@Service
public class QueryStuNumberService {
	
	@Autowired
	private QueryStuNumberDao queryStuNumberDao;
	/**
	 * 查询学生人数
	 * @param stuInfoEntity
	 * @return
	 * @throws Exception
	 */
	public StuInfoEntity QueryStuNumber(StuInfoEntity stuInfoEntity) throws Exception {
		StuInfoEntity StuEntity = new StuInfoEntity();
		List<StuInfoEntity> qSber = queryStuNumberDao.QueryStuNumber(stuInfoEntity);
		StuEntity.setAllPeoNumber(queryStuNumberDao.QueryNumber(stuInfoEntity));
		StuEntity.setPeoNumber(Integer.parseInt(qSber.get(0).getGenderNumber())+Integer.parseInt(qSber.get(1).getGenderNumber()));
		for(int i=0;i<qSber.size();i++){
			String gender = qSber.get(i).getGender();
			if("1".equals(gender)){
				StuEntity.setManNumber(qSber.get(i).getGenderNumber());
			}else{
				StuEntity.setWomanNumber(qSber.get(i).getGenderNumber());
			}
		}
		return StuEntity;
	}
	/**
	 * 显示年级
	 * @return
	 */
	public String[] getGrade(){
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		String[] num = new String[11];
		num[0] = String.valueOf(year-5);
		num[1] = String.valueOf(year-4);
		num[2] = String.valueOf(year-3);
		num[3] = String.valueOf(year-2);
		num[4] = String.valueOf(year-1);
		num[5] = String.valueOf(year);
		num[6] = String.valueOf(year+1);
		num[7] = String.valueOf(year+2);
		num[8] = String.valueOf(year+3);
		num[9] = String.valueOf(year+4);
		num[10] = String.valueOf(year+5);
		return num;
	}
}
